﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using Star_Helper;
using System.Text;
using System.Collections.Generic;
using System.IO;

public class Handler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        //  context.Response.Write("Hello World");
        dataFunc d = new dataFunc();
        string sx = context.Request["name"].ToString();
        // context.Response.form("name")
        erlog(sx);
        if (sx != null)
        {
           // sx = @"<div>这是测试</div>";
            context.Response.Write(sx);//登陆成功要写回主页
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    public string writeM()
    {

        dataFunc d = new dataFunc();


        string sx = @"dsfsfsdfsdffd
                sdfsdfsfdsdfsdfsffsfsf";


        return sx;
    }

    public void erlog(string s)
    {
        string filePath = "E:\\log\\log2.txt";
        using (FileStream fs = File.Create(filePath))
        {
            StreamWriter sw = new StreamWriter(fs);
            fs.SetLength(0);//把文件清空
            sw.Write(s);//写入字符串。
            sw.Close();
        }

    }

    /*实现一个元素拼接方法*/
    public string credDom(string s1, params string[] s2)
    {
        StringBuilder s = new StringBuilder();
        string sx1 = "";
        string sx2 = "";
        if (s2.Length == 1)
        {
            sx1 = s2[0];
        }
        if (s2.Length == 2)
        {
            sx1 = s2[0];
            sx2 = s2[1];
        }
        s.AppendFormat("<{0} class='{2}'> \n {1} \n </{0}>", s1, sx1, sx2);

        return s.ToString();
    }

    public string creadDiv(params string[] s2)
    {
        StringBuilder s = new StringBuilder();
        string sx1 = "";
        string sx2 = "";
        if (s2.Length == 1)
        {
            sx1 = s2[0];
        }
        if (s2.Length == 2)
        {
            sx1 = s2[0];
            sx2 = s2[1];
        }
        s.AppendFormat("<div class='{2}'> \n {1} \n </{div>", sx1, sx2);

        return s.ToString();
    }
    public string creadTable(List<string> s1)
    {
        int cnt = 6;
        StringBuilder sx = new StringBuilder();
        StringBuilder s = new StringBuilder();
        int k = s1.Count % cnt;
        int len = (cnt - k);

        for (int j = 0; j < len; j++)
        {
            s1.Add("");
        }
        for (int i = 1; i <= s1.Count; i++)
        {
            s.Append(credDom("td", s1[i - 1]));
            if (i % cnt == 0)
            {
                sx.Append(credDom("tr", s.ToString()));
                s = new StringBuilder();
            }
        }
        return new StringBuilder().AppendFormat("<table border='1'> \n {0} \n </table>", sx).ToString();

    }

}

